/**
 * 
 */
package com.xac.biz.friend.logic;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;

import android.util.Log;

import com.xac.aas.model.UserInfo;
import com.xac.common.data.DataManager;

/**
 * @author daisongwan
 * 
 */
public class FriendManager {

	private static final FriendManager instance = new FriendManager();
	private FriendManager(){
		
	}
	// TODO Maybe should use singleton.
	public static FriendManager getInstance() {
		return instance;
	}

	public List<UserInfo> retrieveFriendList(){
		Roster roster = DataManager.getInstance().getConnection().getRoster();
		Collection<RosterEntry> entries = roster.getEntries();
		//Collection<RosterGroup> entriesGroup = roster.getGroups();
		List<UserInfo> friendList = new ArrayList<UserInfo>();
		Log.d("FriendManager", "friend size:" + entries.size());
		for (RosterEntry entry : entries) {
			//Presence presence = roster.getPresence(entry.getUser());
			UserInfo friend = new UserInfo();
			Log.d("FriendManager", "friend name:" + entry.getName());
			friend.setUsername(entry.getName());
			String user = entry.getUser();
			Log.d("FriendManager", "user:" + user);
			friend.setUser(entry.getUser());
			/*user.setType(entry.getType());
			user.setSize(entry.getGroups().size());
			user.setStatus(presence.getStatus());
			user.setFrom(presence.getFrom());*/
			friendList.add(friend);
		}
		return friendList;
	}
}
